<?php

/**
 * This is the model class for table "goods".
 *
 * The followings are the available columns in table 'goods':
 * @property integer $id
 * @property string $name
 * @property string $goodsnum
 * @property integer $typeid
 * @property string $size
 * @property string $unit
 * @property double $price
 * @property string $indate
 * @property string $memo
 */
class Goods extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Goods the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'goods';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, typeid', 'required'),
			array('typeid', 'numerical', 'integerOnly'=>true),
			array('price', 'numerical'),
			array('name', 'length', 'max'=>100),
			array('goodsnum', 'length', 'max'=>50),
			array('size', 'length', 'max'=>30),
			array('unit', 'length', 'max'=>10),
			array('memo', 'length', 'max'=>255),
			array('indate', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, goodsnum, typeid, size, unit, price, indate, memo', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
				'goodstype'=>array(self::BELONGS_TO,'GoodsType','typeid')
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '货品ID',
			'name' => '名称',
			'goodsnum' => '货品编号',
			'typeid' => '货品类别',
			'size' => '货品尺寸',
			'unit' => '货品单位',
			'price' => '货品单价',
			'indate' => '最后入库日期',
			'memo' => '备注',
			'goodstype'=>'货物类别'
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('goodsnum',$this->goodsnum,true);
		$criteria->compare('typeid',$this->typeid);
		$criteria->compare('size',$this->size,true);
		$criteria->compare('unit',$this->unit,true);
		$criteria->compare('price',$this->price);
		$criteria->compare('indate',$this->indate,true);
		$criteria->compare('memo',$this->memo,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}